IF EXISTS (SELECT * FROM SYS.VIEWS WHERE name = 'vw_medianamik_OneToManyOption' AND schema_id = SCHEMA_ID('dbo'))
BEGIN
	EXEC('ALTER VIEW vw_medianamik_OneToManyOption
	AS
	SELECT     omr.ForeignTypeId, omr.ForeignPropertyid, pn.NodeId AS PrimaryNodeId, pn.ParentNodeId AS PrimaryParentNodeId, omr.PrimaryTypeId, omr.PrimaryPropertyId, 
                      pn.Path AS PrimaryNodePath
	FROM         dbo.medianamik_Node AS pn INNER JOIN
                      dbo.medianamik_Type AS t ON t.TypeId = pn.TypeId INNER JOIN
                      dbo.vw_medianamik_OneToManyRelation AS omr ON t.Path LIKE ''%'' + CAST(omr.PrimaryTypeId AS NVARCHAR(38)) + ''%''')
END
